package cupiPhoneInterfaz;

import java.awt.BorderLayout;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JButton;

import cupiPhoneMundo.ContactoRepetidoException;
import cupiPhoneMundo.ICupiPhone;

import java.awt.Dimension;

public class NewNum extends JFrame
{

    private static final long serialVersionUID = 1L;
    private JPanel jContentPane = null;
    private JLabel jLabelNomb = null;
    private JLabel jLabelNumero = null;
    private JTextField jTextFieldNombre = null;
    private JTextField jTextFieldNumero = null;
    private JButton jButtonAgreg = null;
    private JButton jButtonExit = null;
    private JLabel jLabelEmail = null;
    private JTextField jTextFieldEmail = null;
    private CupiPhoneInterfaz principal;
    /**
     * This is the default constructor
     */
    public NewNum( CupiPhoneInterfaz xx )
    {
        super( );
        principal = xx;
        initialize( );
    }
    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize( )
    {
        this.setSize( 282, 229 );
        this.setContentPane( getJContentPane( ) );
        this.setTitle( "Agregar contacto" );
    }
    /**
     * This method initializes jContentPane
     * 
     * @return javax.swing.JPanel
     */
    private JPanel getJContentPane( )
    {
        if( jContentPane == null )
        {
            jLabelEmail = new JLabel( );
            jLabelEmail.setBounds( new Rectangle( 10, 87, 124, 33 ) );
            jLabelEmail.setText( "E-mail del contacto" );
            jLabelNumero = new JLabel( );
            jLabelNumero.setBounds( new Rectangle( 10, 47, 124, 33 ) );
            jLabelNumero.setText( "Numero del contacto" );
            jLabelNomb = new JLabel( );
            jLabelNomb.setBounds( new Rectangle( 10, 5, 124, 33 ) );
            jLabelNomb.setText( "Nombre del contacto" );
            jContentPane = new JPanel( );
            jContentPane.setLayout( null );
            jContentPane.add( jLabelNomb, null );
            jContentPane.add( jLabelNumero, null );
            jContentPane.add( getJTextFieldNombre( ), null );
            jContentPane.add( getJTextFieldNumero( ), null );
            jContentPane.add( getJButtonAgreg( ), null );
            jContentPane.add( getJButtonExit( ), null );
            jContentPane.add( jLabelEmail, null );
            jContentPane.add( getJTextFieldEmail( ), null );
        }
        return jContentPane;
    }
    /**
     * This method initializes jTextFieldNombre
     * 
     * @return javax.swing.JTextField
     */
    private JTextField getJTextFieldNombre( )
    {
        if( jTextFieldNombre == null )
        {
            jTextFieldNombre = new JTextField( );
            jTextFieldNombre.setBounds( new Rectangle( 140, 10, 108, 25 ) );
        }
        return jTextFieldNombre;
    }
    /**
     * This method initializes jTextFieldNumero
     * 
     * @return javax.swing.JTextField
     */
    private JTextField getJTextFieldNumero( )
    {
        if( jTextFieldNumero == null )
        {
            jTextFieldNumero = new JTextField( );
            jTextFieldNumero.setBounds( new Rectangle( 140, 52, 108, 25 ) );
        }
        return jTextFieldNumero;
    }
    /**
     * This method initializes jButtonAgreg
     * 
     * @return javax.swing.JButton
     */
    private JButton getJButtonAgreg( )
    {
        if( jButtonAgreg == null )
        {
            jButtonAgreg = new JButton( );
            jButtonAgreg.setBounds( new Rectangle( 17, 129, 112, 35 ) );
            jButtonAgreg.setText( "Agregar" );
            jButtonAgreg.addActionListener( new java.awt.event.ActionListener( )
            {
                public void actionPerformed( java.awt.event.ActionEvent e )
                {

                    String nombre = jTextFieldNombre.getText( );
                    String telefonoCasa = jTextFieldNumero.getText( );
                    String telefonoPersonal = "";
                    String telefonoTrabajo = "";
                    String telefonoCelular = "";
                    String mail = jTextFieldEmail.getText( );

                    if( nombre == null || nombre.equals( "" ) )
                    {
                        JOptionPane.showMessageDialog( null, "Debe ingresar el nombre del contacto", "Error", JOptionPane.ERROR_MESSAGE );
                    }
                    else if( telefonoCasa == null || telefonoCasa.equals( "" ) )
                    {
                        JOptionPane.showMessageDialog( null, "Debe ingresar el telefonoCasa", "Error", JOptionPane.ERROR_MESSAGE );
                    }
                    else if( mail == null || mail.equals( "" ) || mail.indexOf( '@' ) == -1 )
                    {
                        JOptionPane.showMessageDialog( null, "Debe ingresar un mail valido", "Error", JOptionPane.ERROR_MESSAGE );
                    }
                    else
                    {
                        try
                        {
                            principal.agregarContacto( nombre, telefonoCasa, telefonoPersonal,telefonoTrabajo,telefonoCelular, mail );
                            dispose( );
                        }
                        catch( ContactoRepetidoException e1 )
                        {

                        }
                    }

                }
            } );
        }
        return jButtonAgreg;
    }
    /**
     * This method initializes jButtonExit
     * 
     * @return javax.swing.JButton
     */
    private JButton getJButtonExit( )
    {
        if( jButtonExit == null )
        {
            jButtonExit = new JButton( );
            jButtonExit.setBounds( new Rectangle( 138, 129, 112, 35 ) );
            jButtonExit.setText( "Cancelar" );
            jButtonExit.addActionListener( new java.awt.event.ActionListener( )
            {
                public void actionPerformed( java.awt.event.ActionEvent e )
                {
                    dispose( );
                }
            } );
        }
        return jButtonExit;
    }
    /**
     * This method initializes jTextFieldEmail
     * 
     * @return javax.swing.JTextField
     */
    private JTextField getJTextFieldEmail( )
    {
        if( jTextFieldEmail == null )
        {
            jTextFieldEmail = new JTextField( );
            jTextFieldEmail.setBounds( new Rectangle( 140, 89, 108, 25 ) );
        }
        return jTextFieldEmail;
    }

} // @jve:decl-index=0:visual-constraint="10,10"
